<?php include('header.php'); ?>

<?php
$status_array = array("1"=>"已通过","0"=>"待审核","2"=>"已拒绝");

include("/usr/local/apache2/htdocs/jibaiwang/lib/Login.php");
include('log4php/Logger.php');
$cfgfile = "/usr/local/apache2/htdocs/jibaiwang/admin/conf/config.ini";
$defarray = parse_ini_file($cfgfile, 1);
$qlogtag = $defarray["Login"]['qlogtag'];
Logger::configure($defarray["Login"]['qlogcfg']);
$logger = Logger::getLogger($qlogtag);
$host = $defarray["Login"]["host"];
$user = $defarray["Login"]["user"];
$pass = $defarray["Login"]["pass"];
$db = $defarray["Login"]["db"];
$dbh = new Sqlexecutor($host, $user, $pass, $db);
$s = new Login($dbh,$logger);
if($_REQUEST["op"] == "del")
{
    $res = $s->deleteByID($_REQUEST["rule_id"]);
}
if($_REQUEST["op"] == "on")
{
    $res = $s->confirmByID($_REQUEST["rule_id"]);
}
if($_REQUEST["submit"] == "1")
{
    $email = $_REQUEST["email"];
    $username = $_REQUEST["username"];
    $password = $_REQUEST["password"];
    $name = $_REQUEST["name"];
    $tel = $_REQUEST["tel"];
    $corp_name = $_REQUEST["corp_name"];
    $address = $_REQUEST["address"];

    $res = $s->create($email, $username, $password, $name, $tel, $corp_name, $address);
}
$list = $s->getList();

?>

<div id="myModal" class="modal hide fade">
      <div class="modal-header">
          <a class="close" data-dismiss="modal" >&times;</a>
          <h3>新建经销商</h3>
      </div>
    <div class="modal-body">
    <form class="form-horizontal" target="_self">
      <div class="control-group">
          <label class="control-label" for="textarea">用户名</label>
          <div class="controls">
                <input name="username" class="input-xlarge focused" id="username" type="text" value="">
          </div>
          <label class="control-label" for="textarea">密码</label>
            <div class="controls">
                <input name="password" class="input-xlarge focused" id="password" type="password" value="">
            </div>
      </div>

      <div class="control-group">
            <label class="control-label" for="textarea">邮箱</label>
            <div class="controls">
                <input name="email" class="input-xlarge focused" id="email" type="text" value="xx@xx.com">
            </div>
            <label class="control-label" for="textarea">真实姓名</label>
              <div class="controls">
                <input name="name" class="input-xlarge focused" id="name" type="text" value="">
              </div>
            <label class="control-label" for="textarea">真实电话</label>
              <div class="controls">
                <input name="tel" class="input-xlarge focused" id="tel" type="text" value="">
              </div>
        </div>

      <div class="control-group">
            <label class="control-label" for="textarea">公司名称</label>
            <div class="controls">
                <input name="corp_name" class="input-xlarge focused" id="corp_name" type="text" value="">
            </div>
            <label class="control-label" for="textarea">公司地址</label>
              <div class="controls">
                <input name="address" class="input-xlarge focused" id="address" type="text" value="">
              </div>
        </div>

    </div> 
    <div class="modal-footer">
             <button value="1" type="submit" name="submit" class="btn btn-primary" >提交</button>
                  <a href="#" class="btn" data-dismiss="modal">关闭</a>
    </div>
    </form>

 </div>

            <div>
				<ul class="breadcrumb">
					<li>
						<a href="#">系统管理</a> <span class="divider">/</span>
					</li>
					<li>
						<a href="#">经销商管理</a>
					</li>
				</ul>
			</div>
	                <p class="left">
                        <a data-toggle="modal" href="#myModal" class="btn btn-primary visible-desktop">添加新经销商</a>
                    </p>
			<div class="row-fluid sortable">
				<div class="box span12">
					<div class="box-header well" data-original-title>
						<h2><i class="icon-user"></i>经销商管理</h2>
<!--
						<div class="box-icon">
							<a href="#" class="btn btn-setting btn-round"><i class="icon-cog"></i></a>
							<a href="#" class="btn btn-minimize btn-round"><i class="icon-chevron-up"></i></a>
							<a href="#" class="btn btn-close btn-round"><i class="icon-remove"></i></a>
						</div>
-->
					</div>

                    <div class="box-content">

                    <table class="table table-striped bootstrap-datatable datatable">
                    <thead>
                    <tr>
                      <th>#</th>
                      <th>用户名</th>
                      <th>姓名</th>
                      <th>邮箱</th>
                      <th>电话</th>
                      <th>公司名称</th>
                      <th>公司地址</th>
                      <th>状态</th>
                      <th>注册日期</th>
                      <th>操作</th>
                   </tr>
                    </thead>
                    <tbody>
                <?php       
                    foreach($list as $key => $value)
                    {
                        echo "<tr>";
                        echo '<td><input id="b_'.$value["id"].'" type="hidden" class="span1" name="b_id" readonly value="'.$value["id"].'">'.$value["id"  ].'</td>';
                        echo "<td>".$value["username"]."</td>";
                        echo "<td>".$value["name"]."</td>";
                        echo "<td>".$value["email"]."</td>";
                        echo "<td>".$value["tel"]."</td>";
                        echo "<td>".$value["corp_name"]."</td>";
                        echo "<td>".$value["address"]."</td>";
                        echo "<td>";
                        if($value["status"] == 0 ) echo '<span class="label label-warning" >'. $status_array[$value["status"]]."</span></td>";
                        if($value["status"] == 1 ) echo '<span class="label label-success" >'. $status_array[$value["status"]]."</span></td>";
                        echo "<td>".$value["insert_date"]."</td>";
                        echo "<td>";
                        echo '<div class="btn-group"><button  class="btn btn-primary dropdown-toggle" data-toggle="dropdown" href="#">操作<span class="caret"></span></button>';
                        echo '<ul class="dropdown-menu">';
                        echo '<li><a onclick="modify_on('.$value["id"].')"><i class="icon-ok"></i> 审核通过</a></li>';
                        echo '<li><a onclick="modify_del('.$value["id"].')"><i class="icon-trash"></i> 删除</a></li>';
                        echo '<li><a data-toggle="modal" href="?uuid=aa&bba=wef#myModal"  ><i class="icon-pencil"></i> 修改密码</a></li>';
                        echo "</div>";
                        echo "</td>";
                        echo "</tr>";
                    }
                ?>
                    </tbody>
                    </table>

                

                    </div>
				</div><!--/span-->
			
            </div><!--/row-->

<script type="text/javascript">
  function modify_del(id){
          if(window.confirm("确定删除吗？")){
              str="?op=del&rule_id="+id
              window.open(str,'_self');
          }
  }

  function modify_on(id){
            if(window.confirm("确定通过吗？")){
                          str="?op=on&rule_id="+id
                                            window.open(str,'_self');
                                }
              }
</script>

<?php include('footer.php'); ?>
